public class p4 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int n = 999;
		int largestPalindrome = 0;

		for (int i = n; i >= 100; i--) {
			for (int j = i; j >= 100; j--) {
				if (i * j <= largestPalindrome) {
					break;
				}

				if (isPalindrome(i * j)) {
					largestPalindrome = i * j;
					// System.out.println(i + " , " + j + " , " +
					// largestPalindrome);
				}
			}
		}
		System.out.println(largestPalindrome);

		largestPalindrome = 0;
		// advanced method
		// if 6digit number is palindrome, then
		// 100000x+10000y+1000z+100z+10y+x=100001x+10010y+1100z=11(9091x+910y+100z).
		// so a or b should be divided by 11.
		int a, b, divisor;
		a = 999;
		while (a >= 100) {
			if (a % 11 == 0) {
				b = 999;
				divisor = 1;
			} else {
				b = 990;
				divisor = 11;
			}

			while (a <= b) {
				if (a * b <= largestPalindrome) {
					break;
				}

				if (isPalindrome(a * b)) {
					largestPalindrome = a * b;
				}
				b -= divisor;
			}
			a--;
		}
		System.out.println(largestPalindrome);
	}

	static int reverse(int n) {
		int reversed = 0;
		while (n > 0) {
			reversed = 10 * reversed + n % 10;
			n /= 10;
		}
		return reversed;
	}

	static boolean isPalindrome(int n) {
		return n == reverse(n);
	}

	static boolean isPalindromicNum(int n) {
		String s = Integer.toString(n);
		String rev = (new StringBuffer(s)).reverse().toString();

		s = s.substring(0, s.length() / 2);
		rev = rev.substring(0, s.length());

		return s.equalsIgnoreCase(rev);
	}
}
